//
//  AppDelegate.m
//  糖糖大魔王
//
//  Created by 韩震明 on 15/10/21.
//  Copyright © 2015年 韩震明. All rights reserved.
//

#import "AppDelegate.h"
#import "HZMHomePageViewController.h"
#import "HZMOtherShareViewController.h"
#import "HZMSearchViewController.h"
#import "HZMUserViewController.h"
#import "Header.h"
#import "HZMLeadVC.h"
#import "SaveTool.h"
//#import "HZMHomePageTopic.h"



@interface AppDelegate ()

@end

@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    
    [NSThread sleepForTimeInterval:2.0];

    
    HZMHomePageViewController *homePageVC = [[HZMHomePageViewController alloc] init];
    UINavigationController *homePageNaVC = [[UINavigationController alloc] initWithRootViewController:homePageVC];
    homePageNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"iconfont-newspaper.png"] tag:1001] autorelease];
    
    HZMOtherShareViewController *otherShareVC = [[HZMOtherShareViewController alloc] init];
    UINavigationController *otherShareNaVC = [[UINavigationController alloc] initWithRootViewController:otherShareVC];
    otherShareNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"热门" image:[UIImage imageNamed:@"iconfont-heart.png"] tag:1002] autorelease];
    
//    HZMMyShareViewController *myShareVC = [[HZMMyShareViewController alloc] init];
//    UINavigationController *myShareNaVC = [[UINavigationController alloc] initWithRootViewController:myShareVC];
//    myShareNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"dog.png"] tag:1003] autorelease];
    
    HZMSearchViewController *searchVC = [[HZMSearchViewController alloc] init];
    UINavigationController *searchNaVC = [[UINavigationController alloc] initWithRootViewController:searchVC];
    searchNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"搜索" image:[UIImage imageNamed:@"iconfont-search.png"] tag:1004] autorelease];
    
    HZMUserViewController *userVC = [[HZMUserViewController alloc] init];
    UINavigationController *userNaVC = [[UINavigationController alloc] initWithRootViewController:userVC];
    userNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"我" image:[UIImage imageNamed:@"iconfont-happy.png"] tag:1005] autorelease];
    
    
    self.tab = [[UITabBarController alloc] init];
    self.tab.viewControllers = @[homePageNaVC, otherShareNaVC, searchNaVC, userNaVC];
//    self.window.rootViewController = self.tab;
    
    self.tab.tabBar.translucent = NO;
    self.tab.tabBar.tintColor = [UIColor redColor];
    
    /**
     *  ssssss
     */
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults boolForKey:@"firstUse"]) {
        self.window.rootViewController = self.tab;
    }else{
        NSLog(@"22");
        [defaults setBool:YES forKey:@"firstUse"];
        HZMLeadVC *leadVC = [[HZMLeadVC alloc] init];
        self.window.rootViewController = leadVC;
    }
    [defaults synchronize];
    [[UINavigationBar appearance] setBarTintColor:[UIColor grayColor]];
    
    [homePageNaVC release];
    [homePageVC release];
    [_tab release];
    
    //    将channelId:@"Web" 中的Web 替换为您应用的推广渠道。channelId为nil或@""时，默认会被当作@"App Store"渠道。
    [MobClick startWithAppkey:@"56348b9b67e58ecc6300413f" reportPolicy:BATCH   channelId:@""];
    
    [UMSocialData setAppKey:@"56348b9b67e58ecc6300413f"];
    
    
    /**
     *  数据库相关
     */
//    [JRDataBaseManager createTableWithModelClass:[HZMHomePageTopic class]];
    
    
    [SaveTool isHaveFolder];
    
    return YES;
}

- (void)change
{
    if (self.window.alpha == 0.5) {
        self.window.alpha = 1;
    } else {
        self.window.alpha = 0.5;
    }
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
